package cn.lynu.javaweb;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

//http://localhost:8080/web/users
@WebServlet("/demo")
public class Demo1 extends HttpServlet {

    @Override
    protected void doGet(
      HttpServletRequest  req,
      HttpServletResponse resp
    ) throws ServletException, IOException {
        // 设置请求、响应及响应头的字符编码
        req.setCharacterEncoding("utf8");
        resp.setCharacterEncoding("utf8");
        resp.setContentType("text/html;charset=utf-8");


        String username = (String)req.getSession()
                .getAttribute("username");

        PrintWriter out = resp.getWriter();

        if(username==null){
            out.println("用户未登录");
        }else{
            out.println("您好"+username+",欢迎进入本系统");
        }

    }
}
